package zj.it.bhne.gridengineeringsurvey.myutils;

import com.baidu.mapapi.model.LatLng;

public class AngleUtil {


    /**
     * 求B点经纬度
     * @param A 已知点的经纬度，
     * @param distance   AB两地的距离  单位km
     * @param angle  AB连线与正北方向的夹角（0~360）
     * @return  B点的经纬度
     */
    private final static double Rc=6378137;
    private final static double Rj=6356725;
    private double m_RadLo,m_RadLa;
    private double Ec;
    private double Ed;
    public AngleUtil(double longitude,double latitude){
        m_RadLo=longitude*Math.PI/180.;
        m_RadLa=latitude*Math.PI/180.;
        Ec=Rj+(Rc-Rj)*(90.- latitude)/90.;
        Ed=Ec*Math.cos(m_RadLa);
    }


    public static LatLng getMyLatLng(AngleUtil A, double distance, double angle){
        double dx = distance*Math.sin(Math.toRadians(angle));
        double dy= distance*Math.cos(Math.toRadians(angle));
        double bjd=(dx/A.Ed+A.m_RadLo)*180./Math.PI;
        double bwd=(dy/A.Ec+A.m_RadLa)*180./Math.PI;
        return new LatLng(bwd,bjd);
    }
}